'''
@Author: your name
@Date: 2020-02-03 11:53:18
@LastEditTime : 2020-02-05 16:29:46
@LastEditors  : Please set LastEditors
@Description: In User Settings Edit
@FilePath: \pyqt5\demo_017_QObject.py
'''

from PyQt5.Qt import *


class Window(QWidget):
    def __init__(self):
        super().__init__()
        self.setWindowTitle('demo_016_QObject')
        self.resize(500,500)
        self.setup_ui()

    def setup_ui(self):
        self.QObjectProperty()
    
    def QObjectProperty(self):
        # objectname 给Qt对象设置一个名称，这个名称是唯一的，作为对象的ID来使用
        obj = QObject()
        obj.setObjectName('notice')
        print(obj.objectName())
        # property  给Qt对象动态添加一个属性和值
        obj.setProperty('notice_level','error')
        obj.setProperty('notice_level2','warning')
        print(obj.property('notice_level'))
        # 获取对象中所有通过 setProperty 设置的属性名称(key)
        print(obj.dynamicPropertyNames())


if __name__ == '__main__':
    import sys
    app = QApplication(sys.argv)

    win = Window()
    win.show()
    sys.exit(app.exec_())
